﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using AbpZeroTemplate.Authorization;
using AbpZeroTemplate.Editions;
using AbpZeroTemplate.Editions.Dto;
using AbpZeroTemplate.Web.Controllers;
using AbpZeroTemplate.Web.Swagger;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace AbpZeroTemplate.Api.Admin.Controllers
{
    /// <summary>版本信息
    /// </summary>
    [Area("Admin")]
    [Route("Admin/Edition/[action]")]
    [ApiName("Admin")]
    [RemoteService]
    [AbpMvcAuthorize(AppPermissions.Pages_Editions)]
    public class EditionController : AbpZeroTemplateControllerBase
    {
        private readonly IEditionAppService _editionAppService;
        /// <summary>
        /// </summary>
        public EditionController(IEditionAppService editionAppService)
        {
            _editionAppService = editionAppService;
        }

        /// <summary>获取版本信息
        /// </summary>
        [HttpGet]
        public async Task<ListResultDto<EditionListDto>> GetEditions()
        {
            return await _editionAppService.GetEditions();
        }

        /// <summary>获取待编辑的版本
        /// </summary>
        [HttpGet]
        [AbpMvcAuthorize(AppPermissions.Pages_Editions_Create, AppPermissions.Pages_Editions_Edit)]
        public async Task<GetEditionEditOutput> GetEditionForEdit(NullableIdDto input)
        {
            return await _editionAppService.GetEditionForEdit(input);
        }

        /// <summary>创建或者更新版本
        /// </summary>
        [HttpPost]
        [AbpMvcAuthorize(AppPermissions.Pages_Editions_Create, AppPermissions.Pages_Editions_Edit)]
        public async Task CreateOrUpdateEdition([FromBody]CreateOrUpdateEditionDto input)
        {
            await _editionAppService.CreateOrUpdateEdition(input);
        }

        /// <summary>删除版本
        /// </summary>
        [HttpDelete]
        [AbpMvcAuthorize(AppPermissions.Pages_Editions_Delete)]
        public async Task DeleteEdition(EntityDto input)
        {
            await _editionAppService.DeleteEdition(input);
        }

        /// <summary>获取版本的Combobox
        /// </summary>
        [HttpGet]
        public async Task<List<SubscribableEditionComboboxItemDto>> GetEditionComboboxItems(int? selectedEditionId = null)
        {
            return await _editionAppService.GetEditionComboboxItems(selectedEditionId);
        }

    }
}
